package cn.zzu.Etrip.oneday.activity;

import android.app.Fragment;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import com.example.administrator.etrip.R;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class oneday_localfragment extends Fragment {
    ListView listView;
    private String[] places=new String[]{"白马寺","老君山","八达岭","龙门石窟"};
    private String[] descs2 = new String[]
            { "已售646 |4.9分", "已售646 |4.7分", "已售646 |5.0分", "已售646 |4.9分"};
    private String[] descs = new String[]
            { "[白马寺的美]嵩山少林寺、三皇寨一日（含武术表演 上门接）",
                    "[老君山的丽]嵩山少林寺、三皇寨一日（含武术表演 上门接）",
                    "[八达岭的风]嵩山少林寺、三皇寨一日（含武术表演 上门接）",
                    "[龙门石窟]嵩山少林寺、三皇寨一日（含武术表演 上门接）"};
    private String[] descs3= new String[]
            { "出发地：郑州", "出发地：郑州", "出发地：郑州", "出发地：郑州"};
    private String[] descs4= new String[]
            { "$160元起", "$85元起", "$320元起", "$220元起"};
    private int[] price=new int[]{160,85,320,220};
    private double[] happy=new double[]{4.9,4.7,5.0,4.9};
    private int[] imageIds = new int[]
            { R.mipmap.oneday_bg_01, R.drawable.textimage,
                    R.mipmap.text,  R.mipmap.oneday_sm_mudancheng};

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.fragment_local,container,false);

        return view;
    }
    public void onViewCreated(View view,Bundle savedInstanceState){
        super.onViewCreated(view,savedInstanceState);
        List<Map<String, Object>> listItems = new ArrayList<Map<String,Object>>();
        for (int i = 0; i < descs.length; i++) {
            Map<String, Object> listItem = new HashMap<String, Object>();
            listItem.put("header", imageIds[i]);
            listItem.put("place",places[i]);
            listItem.put("descs", descs[i]);
            listItem.put("descs2", descs2[i]);
            listItem.put("descs3", descs3[i]);
            listItem.put("descs4", descs4[i]);
            listItems.add(listItem);
        }
        // 创建一个SimpleAdapter
        SimpleAdapter simpleAdapter = new SimpleAdapter(getActivity().getBaseContext(), listItems,
                R.layout.oneday_locallistview,
                new String[] { "header", "place","descs" , "descs2","descs3","descs4"},
                new int[] { R.id.image11,R.id.place, R.id.text11 , R.id.text22 , R.id.text33 , R.id.text44});
        listView=view.findViewById(R.id.locallistview);
        listView.setAdapter(simpleAdapter);
        // 为ListView的列表项的单击事件绑定事件监听器
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener()
        {
            // 第position项被单击时激发该方法
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id)
            {
                Intent intent=new Intent(getActivity().getBaseContext(),oneday_pay.class);
                Bundle data=new Bundle();
                data.putSerializable("photo",imageIds[position]);
                String tag="position------------";
                Log.d(tag,String.valueOf(position));
                intent.putExtras(data);
                intent.putExtra("价格",price[position]);
                intent.putExtra("xxx",happy[position]);
                intent.putExtra("目的地",places[position]);
                startActivity(intent);
            }
        });

    }
}